
import 'location_info.dart';
import 'dart:convert';

class LocationInfoRes {
    LocationInfo data;
    String direction;
    String requestMethod;
    String responseType;
    int time;

    LocationInfoRes({this.data, this.direction, this.requestMethod, this.responseType, this.time});

    factory LocationInfoRes.fromJson(Map<String, dynamic> json) {
        return LocationInfoRes(
            data: json['data'] != null ? LocationInfo.fromJson(json['data']) : null,
            direction: json['direction'], 
            requestMethod: json['requestMethod'], 
            responseType: json['responseType'], 
            time: json['time'], 
        );
    }

    Map<String, dynamic> toJson() {
        final Map<String, dynamic> data = new Map<String, dynamic>();
        data['direction'] = this.direction;
        data['requestMethod'] = this.requestMethod;
        data['responseType'] = this.responseType;
        data['time'] = this.time;
        if (this.data != null) {
            data['data'] = this.data.toJson();
        }
        return data;
    }

    static List<LocationInfoRes> fromJsonString(json) {
        print(json);
        List<LocationInfoRes> list = [];
//        if (!(json is String) || !json.startsWith('[')) {
//            print('json is not invalid');
//            return [];
//        }

        var jsonArray = jsonDecode(json);
//        jsonArray.forEach((v) {
            list.add(new LocationInfoRes.fromJson(jsonArray));
            print(list);
//        });
        return list;
    }

    String toString() {
        return '{"data":${data
            .toString()},"direction":$direction,"requestMethod":$requestMethod,"responseType":$responseType,"time":$time}';
    }
}